package com.ganlinux.pangoo.dao.model;

import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.ganlinux.pangoo.dao.basemodel.BaseUserFootmarkList;
import com.ganlinux.pangoo.entity.*;
import com.ganlinux.pangoo.entity.response.*;
import com.ganlinux.pangoo.tools.AppUtil;
import com.ganlinux.pangoo.tools.ConstantUtil;
import com.ganlinux.pangoo.tools.EncrypMD5Util;
import com.ganlinux.pangoo.tools.StringUtil;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.IAtom;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;

/**
 * Generated by JFinal.
 */
@SuppressWarnings("serial")
public class UserFootmarkList extends BaseUserFootmarkList<UserFootmarkList> {
	public static final UserFootmarkList dao = new UserFootmarkList();
	//更新行程列表
	public RspFootPrintCreateUpdateData footPrintCreateUpdate(String pin, boolean isnew, FootPrintCreateBean footPrintInfoBean) {
		//Db.update("create table HH if not exists(id int(4) not null primary key auto_increment,name char(20) not null)");
		RspFootPrintCreateUpdateData rspFootPrintCreateUpdateData = new RspFootPrintCreateUpdateData();
		if (isnew) {
			//新建
			UserFootmarkList userFootMarkList = insertFootPrintInfoBeanIntoDbUserFootprintList(pin,footPrintInfoBean);
			if (userFootMarkList != null) {
				rspFootPrintCreateUpdateData.setFootPrintId(userFootMarkList.getFootprintid());
				rspFootPrintCreateUpdateData.setImgUrl(AppUtil.getFileName(userFootMarkList.getImgurl()));
				rspFootPrintCreateUpdateData.setAccessKey("OD2ybcMsX_Q1L7w5YXvaZm5YZOVFn6TGx-AdC-F9");
				rspFootPrintCreateUpdateData.setSecretKey("chWXwGmtW0e08IGdi1mD-0HmDidU6QxY8Nk4nVer");
			}else {
				rspFootPrintCreateUpdateData = null;
			}
		}else {
			//
			UserFootmarkList userTravelList = UserFootmarkList.dao.findFirst("select * from user_footmark_list where userid = '"+pin+"' and footprintid = '"+footPrintInfoBean.getFootprintid()+"'");
			if (userTravelList != null) {
				//更新
				if (footPrintInfoBeanIntoDbUserFootprintList(userTravelList,pin,footPrintInfoBean) > 0) {
					rspFootPrintCreateUpdateData.setFootPrintId(userTravelList.getFootprintid());
					rspFootPrintCreateUpdateData.setImgUrl(AppUtil.getFileName(userTravelList.getImgurl()));
					rspFootPrintCreateUpdateData.setAccessKey("OD2ybcMsX_Q1L7w5YXvaZm5YZOVFn6TGx-AdC-F9");
					rspFootPrintCreateUpdateData.setSecretKey("chWXwGmtW0e08IGdi1mD-0HmDidU6QxY8Nk4nVer");
				}else{
					rspFootPrintCreateUpdateData = null;
				}
			}else {
				rspFootPrintCreateUpdateData = null;
			}

		}

		return rspFootPrintCreateUpdateData;
	}
	public FootPrintSimpleInfoBean getFootPrintSimpleInfoBean(String pin, int footmarkId){
		final UserFootmarkList currentUserFootMarkList = findFirst("select * from user_footmark_list where pin = '" + pin + "' and footprintid = '" + footmarkId + "'");

		if (currentUserFootMarkList != null){
			FootPrintSimpleInfoBean footPrintSimpleInfoBean = new FootPrintRecommendedSimpleInfoBean();
			footPrintSimpleInfoBean.setFootPrintId(currentUserFootMarkList.getFootprintid());
			footPrintSimpleInfoBean.setState(currentUserFootMarkList.getState());
			footPrintSimpleInfoBean.setLable(currentUserFootMarkList.getLable());
			footPrintSimpleInfoBean.setFootPrintTime(currentUserFootMarkList.getFootprinttime());
			footPrintSimpleInfoBean.setCountryName(currentUserFootMarkList.getCountryname());
			footPrintSimpleInfoBean.setProvinceName(currentUserFootMarkList.getProvincename());
			footPrintSimpleInfoBean.setCityName(currentUserFootMarkList.getCityname());
			footPrintSimpleInfoBean.setDistrictName(currentUserFootMarkList.getDistrictname());
			footPrintSimpleInfoBean.setPlaceName(currentUserFootMarkList.getPlacename());
			if (currentUserFootMarkList.getImgcnt() > 0) {
				String[]suffuxNames = AppUtil.convertSuffixNameToArray(currentUserFootMarkList.getImgfmt(), currentUserFootMarkList.getImgcnt());
				footPrintSimpleInfoBean.setImgUrl(currentUserFootMarkList.getImgurl()+"0."+suffuxNames[0]);
			}

			footPrintSimpleInfoBean.setImgCnt(currentUserFootMarkList.getImgcnt());
			return footPrintSimpleInfoBean;
		}

		return null;
	}

	//获取行程概况列表
	public RspFootPrintSimpleInfoListData getFootTravelSimpleinfoList(String pin, int sorttype, int page, int pagesize) {
		RspFootPrintSimpleInfoListData rspGetUsersTravelData = new RspFootPrintSimpleInfoListData();
		List<FootPrintSimpleInfoBean> travelSimpleBeans = new ArrayList<FootPrintSimpleInfoBean>();
		//		List<UserFootMarkList> usersTravels;
		String selectString = "";
		if (sorttype == ConstantUtil.SORTTYPE_CREATTTIME) {
			selectString = "from user_footmark_list where pin = '"+pin+"' order by createtime desc";
			//			usersTravels = UserFootMarkList.dao.find("select * from user_footmark_list where userid = '"+userid+"' order by createtime desc");
		}else if(sorttype == ConstantUtil.SORTTYPE_FOOTPRINTTIME){

			selectString = "from user_footmark_list where pin = '"+pin+"' order by footprinttime desc";
			//			Page<UserFootMarkList> results = paginate(page, pagesize, "select *", selectString);
			//			usersTravels = results.getList();
			//			usersTravels = UserFootMarkList.dao.find("select * from user_footmark_list where userid = '"+userid+"' order by footprinttime desc");
		}else {
			selectString = "from user_footmark_list where pin = '"+pin+"' order by lastedittime desc";
			//			usersTravels = UserFootMarkList.dao.find("select * from user_footmark_list where userid = '"+userid+"' order by lastedittime desc");
		}
		Page<UserFootmarkList> results = paginate(page, pagesize, "select *", selectString);
		List<UserFootmarkList> usersTravels = results.getList();
		int size = usersTravels.size();
		for (int i = 0; i < size; i++) {
			UserFootmarkList currentUserFootMarkList = usersTravels.get(i);
			FootPrintSimpleInfoBean footPrintSimpleInfoBean = new FootPrintSimpleInfoBean();
			footPrintSimpleInfoBean.setFootPrintId(currentUserFootMarkList.getFootprintid());
			footPrintSimpleInfoBean.setState(currentUserFootMarkList.getState());
			footPrintSimpleInfoBean.setLable(currentUserFootMarkList.getLable());
			footPrintSimpleInfoBean.setFootPrintTime(currentUserFootMarkList.getFootprinttime());
			footPrintSimpleInfoBean.setCountryName(currentUserFootMarkList.getCountryname());
			footPrintSimpleInfoBean.setProvinceName(currentUserFootMarkList.getProvincename());
			footPrintSimpleInfoBean.setCityName(currentUserFootMarkList.getCityname());
			footPrintSimpleInfoBean.setDistrictName(currentUserFootMarkList.getDistrictname());
			footPrintSimpleInfoBean.setPlaceName(currentUserFootMarkList.getPlacename());
			if (currentUserFootMarkList.getImgcnt() > 0) {
				String[]suffuxNames = AppUtil.convertSuffixNameToArray(currentUserFootMarkList.getImgfmt(), currentUserFootMarkList.getImgcnt());
				footPrintSimpleInfoBean.setImgUrl(currentUserFootMarkList.getImgurl()+"0."+suffuxNames[0]);
			}

			footPrintSimpleInfoBean.setImgCnt(currentUserFootMarkList.getImgcnt());
			travelSimpleBeans.add(footPrintSimpleInfoBean);

		}
		rspGetUsersTravelData.setFootPrintSimpleInfoBeanList(travelSimpleBeans);
		rspGetUsersTravelData.setPageIndex(results.getPageNumber());
		rspGetUsersTravelData.setTotal(results.getTotalRow());
		rspGetUsersTravelData.setTotalPage(results.getTotalPage());
		return rspGetUsersTravelData;

	}

	//获取推荐足迹列表
	public RspFootPrintSimpleInfoListData getRecommendedFootMarkList(String pin, int page, int pagesize) {
		RspFootPrintSimpleInfoListData rspGetUsersTravelData = new RspFootPrintSimpleInfoListData();
		List<FootPrintSimpleInfoBean> travelSimpleBeans = new ArrayList<FootPrintSimpleInfoBean>();
		//		List<UserFootMarkList> usersTravels;
		String selectString = "";
		/*if (sorttype == ConstantUtil.SORTTYPE_CREATTTIME) {
			selectString = "from user_footmark_list where pin = '"+pin+"' order by createtime desc";
			//			usersTravels = UserFootMarkList.dao.find("select * from user_footmark_list where userid = '"+userid+"' order by createtime desc");
		}else if(sorttype == ConstantUtil.SORTTYPE_FOOTPRINTTIME){

			selectString = "from user_footmark_list where pin = '"+pin+"' order by footprinttime desc";
			//			Page<UserFootMarkList> results = paginate(page, pagesize, "select *", selectString);
			//			usersTravels = results.getList();
			//			usersTravels = UserFootMarkList.dao.find("select * from user_footmark_list where userid = '"+userid+"' order by footprinttime desc");
		}else {
			selectString = "from user_footmark_list where pin = '"+pin+"' order by lastedittime desc";
			//			usersTravels = UserFootMarkList.dao.find("select * from user_footmark_list where userid = '"+userid+"' order by lastedittime desc");
		}
		Page<UserFootMarkList> results = paginate(page, pagesize, "select *", selectString);
		List<UserFootMarkList> usersTravels = results.getList();
		int size = usersTravels.size();
		for (int i = 0; i < size; i++) {
			UserFootMarkList currentUserFootMarkList = usersTravels.get(i);
			FootPrintSimpleInfoBean footPrintSimpleInfoBean = new FootPrintSimpleInfoBean();
			footPrintSimpleInfoBean.setFootPrintId(currentUserFootMarkList.getFootprintid());
			footPrintSimpleInfoBean.setState(currentUserFootMarkList.getState());
			footPrintSimpleInfoBean.setLable(currentUserFootMarkList.getLable());
			footPrintSimpleInfoBean.setFootPrintTime(currentUserFootMarkList.getFootprinttime());
			footPrintSimpleInfoBean.setCountryName(currentUserFootMarkList.getCountryname());
			footPrintSimpleInfoBean.setProvinceName(currentUserFootMarkList.getProvincename());
			footPrintSimpleInfoBean.setCityName(currentUserFootMarkList.getCityname());
			footPrintSimpleInfoBean.setDistrictName(currentUserFootMarkList.getDistrictname());
			footPrintSimpleInfoBean.setPlaceName(currentUserFootMarkList.getPlacename());
			if (currentUserFootMarkList.getImgcnt() > 0) {
				String[]suffuxNames = AppUtil.convertSuffixNameToArray(currentUserFootMarkList.getImgfmt(), currentUserFootMarkList.getImgcnt());
				footPrintSimpleInfoBean.setImgUrl(currentUserFootMarkList.getImgurl()+"0."+suffuxNames[0]);
			}

			footPrintSimpleInfoBean.setImgCnt(currentUserFootMarkList.getImgcnt());
			travelSimpleBeans.add(footPrintSimpleInfoBean);

		}
		rspGetUsersTravelData.setFootPrintSimpleInfoBeanList(travelSimpleBeans);
		rspGetUsersTravelData.setPageIndex(results.getPageNumber());
		rspGetUsersTravelData.setTotal(results.getTotalRow());
		rspGetUsersTravelData.setTotalPage(results.getTotalPage());*/
		return rspGetUsersTravelData;

	}

	//获取行程概况列表
	public RspFootPrintMapInfoListData getFootTravelMapInfoList(String pin, String countryId, String provinceId, String cityId, String districtId, int type) {
		RspFootPrintMapInfoListData rspFootPrintMapInfoListData = new RspFootPrintMapInfoListData();
		List<CountryBean> countryBeanList = new ArrayList<CountryBean>();
		List<ProvinceBean> provinceBeanList = new ArrayList<ProvinceBean>();
		List<CityBean> cityBeanList = new ArrayList<CityBean>();
		List<DistrictBean> districtBeanList = new ArrayList<DistrictBean>();
		List<PlaceBean> placeBeanList = new ArrayList<PlaceBean>();
		List<UserFootmarkList> usersTravels = new ArrayList<UserFootmarkList>();
		String selectString = "";
		switch (type) {
			case 1://获取国家列表
				List<Record> c_records= Db.find("select distinct countryid from user_footmark_list where pin = '"+pin+"'");
				for (int i = 0; i < c_records.size(); i++) {

					String t_countryid = c_records.get(i).getStr("countryid");
					CountryBean countryBean = new CountryBean();
					List<UserFootmarkList> userFootMarkList = UserFootmarkList.dao.find("select * from user_footmark_list where pin = '"+pin+"' and countryid = '"+t_countryid+"'");
					usersTravels.addAll(userFootMarkList);
					countryBean.setCountryId(t_countryid);
					countryBean.setCountryName(userFootMarkList.get(0).getCountryname());
					countryBean.setTotal(userFootMarkList.size());
					countryBeanList.add(countryBean);
				}

				break;
			case 2://获取省列表
				List<Record> p_records= Db.find("select distinct provinceid from user_footmark_list where pin = '"+pin+"' and countryid = '"+countryId+"'");
				for (int i = 0; i < p_records.size(); i++) {

					String t_provinceid = p_records.get(i).getStr("provinceid");
					ProvinceBean provinceBean = new ProvinceBean();
					List<UserFootmarkList> userFootMarkList = UserFootmarkList.dao.find("select * from user_footmark_list where pin = '"+pin+"' and countryid = '"+countryId+"' and provinceid = '"+t_provinceid +"'");
					usersTravels.addAll(userFootMarkList);
					provinceBean.setProvinceId(t_provinceid);
					provinceBean.setProvinceName(userFootMarkList.get(0).getProvincename());
					provinceBean.setTotal(userFootMarkList.size());
					provinceBeanList.add(provinceBean);
				}
				break;
			case 3://获取市列表
				List<Record> city_records= Db.find("select distinct cityid from user_footmark_list where  userid = '"+pin+"' and pin = '"+countryId+"' and provinceid = '"+provinceId +"'");
				for (int i = 0; i < city_records.size(); i++) {

					String t_cityid = city_records.get(i).getStr("cityid");
					CityBean cityBean = new CityBean();
					List<UserFootmarkList> userFootMarkList = UserFootmarkList.dao.find("select * from user_footmark_list where pin = '"+pin+"' and countryid = '"+countryId+"' and provinceid = '"+provinceId +"' and cityid = '"+t_cityid+"'");
					usersTravels.addAll(userFootMarkList);
					cityBean.setCityId(t_cityid);
					cityBean.setCityName(userFootMarkList.get(0).getCityname());
					cityBean.setTotal(userFootMarkList.size());
					cityBeanList.add(cityBean);
				}
				break;
			case 4://获取区域列表
				List<Record> d_records= Db.find("select distinct districtid from user_footmark_list  where   pin = '"+pin+"' and countryid = '"+countryId+"' and provinceid = '"+provinceId +"' and cityid = '"+cityId+"'");
				for (int i = 0; i < d_records.size(); i++) {

					String t_districtid = d_records.get(i).getStr("districtid");
					DistrictBean districtBean = new DistrictBean();
					List<UserFootmarkList> userFootMarkList =  UserFootmarkList.dao.find("select * from user_footmark_list where pin = '"+pin+"' and countryid = '"+countryId+"' and provinceid = '"+provinceId +"' and cityid = '"+cityId+"' and districtid = '"+ t_districtid +"'");
					usersTravels.addAll(userFootMarkList);
					districtBean.setDistrictId(t_districtid);
					districtBean.setDistrictName(userFootMarkList.get(0).getDistrictname());
					districtBean.setTotal(userFootMarkList.size());
					districtBeanList.add(districtBean);
				}
				break;
			case 5://获取区县的足迹列表
				usersTravels = UserFootmarkList.dao.find("select * from user_footmark_list where pin = '"+pin+"' and countryid = '"+countryId+"' and provinceid = '"+provinceId +"' and cityid = '"+cityId+"' and districtid = '"+ districtId +"'");

				break;

			default:
				break;
		}
		for (int i = 0; i < usersTravels.size(); i++) {
			placeBeanList.add(userFootprintListToPlaceBean(usersTravels.get(i)));
		}
		rspFootPrintMapInfoListData.setType(type);
		rspFootPrintMapInfoListData.setCountryBeanList(countryBeanList);
		rspFootPrintMapInfoListData.setProvinceBeanList(provinceBeanList);
		rspFootPrintMapInfoListData.setCityBeanList(cityBeanList);
		rspFootPrintMapInfoListData.setDistrictBeanList(districtBeanList);
		rspFootPrintMapInfoListData.setPlaceBeanList(placeBeanList);


		return rspFootPrintMapInfoListData;

	}


	//获取行程列表详情
	public RspFootPrintInfoData getFootPrintInfo(String pin, int footprintid) {
		RspFootPrintInfoData rspFootPrintInfoData = new RspFootPrintInfoData();
		if (!StringUtil.isEmpty(pin) && footprintid > 0) {
			FootPrintInfoBean footPrintInfoBean = new FootPrintInfoBean();

			UserFootmarkList userFootprintInfo = findFirst("select * from user_footmark_list where pin = ? and footprintid = ?",pin,footprintid);
			if (userFootprintInfo != null) {
				footPrintInfoBean.setFootprintid(userFootprintInfo.getFootprintid());
				footPrintInfoBean.setState(userFootprintInfo.getState());
				footPrintInfoBean.setLable(userFootprintInfo.getLable());
				footPrintInfoBean.setFootprinttime(userFootprintInfo.getFootprinttime());
				AreaDivision areaDivision = new AreaDivision();
				areaDivision.setCountryId(userFootprintInfo.getCountryid());
				areaDivision.setCountryName(userFootprintInfo.getCountryname());
				areaDivision.setProvinceId(userFootprintInfo.getProvinceid());
				areaDivision.setProvinceName(userFootprintInfo.getProvincename());
				areaDivision.setCityId(userFootprintInfo.getCityid());
				areaDivision.setCityName(userFootprintInfo.getCityname());
				areaDivision.setDistrictId(userFootprintInfo.getDistrictid());
				areaDivision.setDistrictName(userFootprintInfo.getDistrictname());
				areaDivision.setPlaceId(userFootprintInfo.getPlaceid());
				areaDivision.setPlaceName(userFootprintInfo.getPlacename());
				areaDivision.setPlaceLocation(userFootprintInfo.getPlacelocation());
				footPrintInfoBean.setAreaDivision(areaDivision);
				int size = userFootprintInfo.getImgcnt();
				List<String> imgUrls = new ArrayList<String>(size);
				if (size > 0) {
					String[]suffuxNames = AppUtil.convertSuffixNameToArray(userFootprintInfo.getImgfmt(),size);
					for (int i = 0; i < size; i++) {
						String url = userFootprintInfo.getImgurl()+i+"."+suffuxNames[i];
						imgUrls.add(url);
					}
					footPrintInfoBean.setImgUrls(imgUrls);
				}else{
					footPrintInfoBean.setImgUrls(imgUrls);
				}

				footPrintInfoBean.setCreatetime(userFootprintInfo.getCreatetime());
				rspFootPrintInfoData.setFootPrintInfoBean(footPrintInfoBean);
			}else {
				rspFootPrintInfoData = null;
			}
		}else {
			rspFootPrintInfoData = null;
		}
		return rspFootPrintInfoData;
	}
	//删除行程列表
	public RspFootPrintDeleteData deleteFootPrint(final String pin, final int footprintid) {
		if (!StringUtil.isEmpty(pin) && footprintid > 0) {
			RspFootPrintDeleteData rspFootPrintDeleteData = new RspFootPrintDeleteData();
			boolean issuccess = false;
			issuccess = Db.tx(new IAtom(){
				public boolean run() throws SQLException {
					return Db.update("delete from user_footmark_list where pin = ? and footprintid = ?",pin,footprintid)>0;
				}
			});
			if (issuccess) {
				return rspFootPrintDeleteData;
			}
		}
		return null;
	}

	private int footPrintInfoBeanIntoDbUserFootprintList(UserFootmarkList userFootMarkList, String pin, FootPrintCreateBean footPrintInfoBean) {
		boolean issuccess = false;

		userFootMarkList.setPin(pin);
		userFootMarkList.setFootprintid(2);
		userFootMarkList.setState(footPrintInfoBean.getState());
		userFootMarkList.setLable(footPrintInfoBean.getLable());
		userFootMarkList.setFootprinttime(footPrintInfoBean.getFootprinttime());
		userFootMarkList.setCountryid(footPrintInfoBean.getAreaDivision().getCountryId());
		userFootMarkList.setCountryname(footPrintInfoBean.getAreaDivision().getCountryName());
		userFootMarkList.setProvinceid(footPrintInfoBean.getAreaDivision().getProvinceId());
		userFootMarkList.setProvincename(footPrintInfoBean.getAreaDivision().getProvinceName());
		userFootMarkList.setCityid(footPrintInfoBean.getAreaDivision().getCityId());
		userFootMarkList.setCityname(footPrintInfoBean.getAreaDivision().getCityName());
		userFootMarkList.setDistrictid(footPrintInfoBean.getAreaDivision().getPlaceId());
		userFootMarkList.setDistrictname(footPrintInfoBean.getAreaDivision().getDistrictName());
		userFootMarkList.setPlaceid(footPrintInfoBean.getAreaDivision().getPlaceId());
		userFootMarkList.setPlacename(footPrintInfoBean.getAreaDivision().getPlaceName());
		userFootMarkList.setPlacelocation(footPrintInfoBean.getAreaDivision().getPlaceLocation());
		userFootMarkList.setImgurl(footPrintInfoBean.getImgUrl());
		userFootMarkList.setImgcnt(footPrintInfoBean.getImgCnt());
		userFootMarkList.setImgfmt(footPrintInfoBean.getImgFmt());
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm");
		Date date1 = new Date();
		if (footPrintInfoBean.getCreatetime() == null) {
			userFootMarkList.setCreatetime(sdf.format(date1));
		}else {
			userFootMarkList.setCreatetime(footPrintInfoBean.getCreatetime());
		}
		userFootMarkList.setLastedittime(sdf.format(date1));
		final UserFootmarkList userFootMarkList1 = userFootMarkList;
		issuccess = Db.tx(new IAtom(){
			public boolean run() throws SQLException {
				return userFootMarkList1.update();
			}
		});

		if (issuccess) {
			return userFootMarkList1.getFootprintid();
		}
		return -1;

	}
	private UserFootmarkList insertFootPrintInfoBeanIntoDbUserFootprintList(String pin, FootPrintCreateBean footPrintInfoBean) {
		boolean issuccess = false;
		UserFootmarkList userFootMarkList = new UserFootmarkList();
//		userFootMarkList.setUserid(userid);
		//		userFootMarkList.setFootprintid(2);
		userFootMarkList.setPin(pin);
		userFootMarkList.setState(footPrintInfoBean.getState());
		userFootMarkList.setLable(footPrintInfoBean.getLable());
		userFootMarkList.setFootprinttime(footPrintInfoBean.getFootprinttime());
		userFootMarkList.setCountryid(footPrintInfoBean.getAreaDivision().getCountryId());
		userFootMarkList.setCountryname(footPrintInfoBean.getAreaDivision().getCountryName());
		userFootMarkList.setProvinceid(footPrintInfoBean.getAreaDivision().getProvinceId());
		userFootMarkList.setProvincename(footPrintInfoBean.getAreaDivision().getProvinceName());
		userFootMarkList.setCityid(footPrintInfoBean.getAreaDivision().getCityId());
		userFootMarkList.setCityname(footPrintInfoBean.getAreaDivision().getCityName());
		userFootMarkList.setDistrictid(footPrintInfoBean.getAreaDivision().getDistrictId());
		userFootMarkList.setDistrictname(footPrintInfoBean.getAreaDivision().getDistrictName());
		userFootMarkList.setPlaceid(footPrintInfoBean.getAreaDivision().getPlaceId());
		userFootMarkList.setPlacename(footPrintInfoBean.getAreaDivision().getPlaceName());
		userFootMarkList.setPlacelocation(footPrintInfoBean.getAreaDivision().getPlaceLocation());
		userFootMarkList.setImgurl(footPrintInfoBean.getImgUrl());
		userFootMarkList.setImgcnt(footPrintInfoBean.getImgCnt());
		userFootMarkList.setImgfmt(footPrintInfoBean.getImgFmt());
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm");
		Date date1 = new Date();
		if (footPrintInfoBean.getCreatetime() == null) {
			userFootMarkList.setCreatetime(sdf.format(date1));
		}else {
			userFootMarkList.setCreatetime(footPrintInfoBean.getCreatetime());
		}
		userFootMarkList.setLastedittime(sdf.format(date1));
		final UserFootmarkList userFootMarkList1 = userFootMarkList;
		issuccess = Db.tx(new IAtom(){
			public boolean run() throws SQLException {
				return userFootMarkList1.save();
			}
		});
		String imgTocken = EncrypMD5Util.MD5(""+pin+footPrintInfoBean.getFootprintid()+footPrintInfoBean.getLable());
		userFootMarkList1.setImgurl(AppUtil.getImgTockenUrl(pin, userFootMarkList1.getFootprintid(),imgTocken));
		if (issuccess) {
			issuccess = Db.tx(new IAtom(){
				public boolean run() throws SQLException {
					boolean reslt = userFootMarkList1.update();
					return reslt;
				}
			});
		}

		if (issuccess) {
			return userFootMarkList1;
		}
		return null;

	}



	private PlaceBean userFootprintListToPlaceBean(UserFootmarkList userFootMarkList) {
		PlaceBean placeBean = new PlaceBean();
		placeBean.setPlaceLocation(userFootMarkList.getPlacelocation());
		placeBean.setPlaceName(userFootMarkList.getPlacename());
		placeBean.setTime(userFootMarkList.getFootprinttime());
		placeBean.setFootPrintId(userFootMarkList.getFootprintid());
		return placeBean;
	}


	//获取行程统计
	public RspFootMarkStatisticsData getFootMarkStatistics(String pin) {
		RspFootMarkStatisticsData rspFootMarkStatisticsData = new RspFootMarkStatisticsData();
		Long footPrintNum = Db.queryLong("select count(distinct footprintid) from user_footmark_list where pin = '"+pin+"'");
		Long countryNum = Db.queryLong("select count(distinct countryid) from user_footmark_list where pin = '"+pin+"'");
		Long provinceNum = Db.queryLong("select count(distinct provinceid) from user_footmark_list where pin = '"+pin+"'");
		Long cityNum = Db.queryLong("select count(distinct cityid) from user_footmark_list where pin = '"+pin+"'");
		Long districtNum = Db.queryLong("select count(distinct districtid) from user_footmark_list where pin = '"+pin+"'");
		rspFootMarkStatisticsData.setFootPrintNum(footPrintNum.intValue());
		rspFootMarkStatisticsData.setCountryNum(countryNum.intValue());
		rspFootMarkStatisticsData.setProvinceNum(provinceNum.intValue());
		rspFootMarkStatisticsData.setCityNum(cityNum.intValue());
		rspFootMarkStatisticsData.setDistrictNum(districtNum.intValue());
		return rspFootMarkStatisticsData;
	}
}
